import { Model } from '@vuex-orm/core';
import {getToken} from "../utils/auth";
import MinishopSku from "./MinishopSku";
import MinishopSkuAttrs from "./MinishopSkuAttrs";

export default class MinishopSpu extends Model {
    // This is the name used as module name of the Vuex Store.
    static entity = 'minishop_spu';

    // List of all fields (schema) of the post model. `this.attr` is used
    // for the generic field type. The argument is the default value.
    static fields() {
        return {
            id: this.attr(null),
            product_id: this.number(''),
            out_product_id: this.string(''),
            title: this.string(''),
            sub_title: this.string(''),
            head_img: this.string(''),
            desc_info: this.string(''),
            brand_id: this.number(''),
            status: this.number(''),
            edit_status: this.number(''),
            min_price: this.number(''),
            cats: this.string(''),
            attrs: this.string(''),
            model: this.string(''),
            dispatch_type: this.string(''),
            express_info: this.string(''),
            shopcat: this.string(''),
            skus: this.string(''),
            sales_count: this.number(''),
            weigh: this.number(''),
            template_id: this.string(''),
            ext_json: this.string(''),
            memo: this.string(''),
            ext_attrs: this.string(''),
            creator_id: this.attr(''),
            created_at: this.attr(''),
            updated_at: this.attr(''),
            deleted_at: this.attr(0),
            spuskus:this.hasMany(MinishopSku,'out_product_id','out_product_id'),
            sku_attrs:this.hasMany(MinishopSkuAttrs,'spu_id','out_product_id'),
        };
    }

    static fetchById(params) {
        return this.api().get(`/minishop/goods/detail`,{params: params, persistBy: 'create' });
    }

}
